package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class LoginDemo {
    public static void main(String[] args) {
        UserInfo userinfo = InputUtil.getInputObject(new UserInfo(), "苨冲q币马", "登录");
        System.out.println(userinfo);

        try (
                Connection conn = DBUtil.getConnection()
        ) {
            Statement stmt = conn.createStatement();
            String sql = "SELECT id,username,password,nickname,age " +
                        "FROM userinfo " +
                        "WHERE username='" + userinfo.getUsername() +
                        " 'AND password=' " + userinfo.getPassword() + "'";
            ResultSet rs = stmt.executeQuery(sql);
            if(rs.next()){
                System.out.println("登录成功");
            }else{
                System.out.println("登录失败");
            }

//            while (rs.next()){
//              System.out.println(rs.getInt("id"));
//              System.out.println(rs.getString("username"));
//              System.out.println(rs.getString("password"));
//              System.out.println(rs.getString("nickname"));
//              System.out.println(rs.getInt("age"));
//          }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
